let str = '2019-01-14' 
//ES2018正则中分组用括号，命名用(?<name>)
let reg = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/
let {year,month,day} = str.match(reg).groups
console.log(year,month,day)  //2019 01 14
console.log('----------------')
//原始反向引用(在正则中引用命名的分组)
let reg2 = /^(张三)-\1$/
console.log(reg2.test('张三-张三'))   //true
console.log('----------------')
//在正则中引用命名的分组：反向引用(\k<name>)
let reg3 = /^(?<name>张三)-\k<name>$/
let a = 'a-a',b='b-c',c='张三-张三'
console.log(reg3.test(a),reg3.test(b),reg3.test(c))  //false false true
//形式转换（替换）
//将'2019-01-14'转换为'2019/01/14'
//使用$1,$2,$3或$<name>
let date = str.replace(reg,'$1/$2/$3')
let date2 = str.replace(reg,'$<year>/$<month>/$<day>')
console.log(date,date2)   //2019/01/14 2019/01/14
//replace()方法使用回调函数
let date3 = str.replace(reg,(...arg)=>{
	let {year,month,day} = arg[arg.length-1]
	return `${year}/${month}/${day}`
})
console.log(date3)  //2019/01/14
//正则：越用越会/越不用越不会
